package com.company.bookstore.mapper.book_module;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.bookstore.entities.book_module.BookCategory;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 姬深威
 * @since 2020-09-12
 */
public interface BookCategoryMapper extends BaseMapper<BookCategory> {

    @Select("SELECT fk_category_id FROM t_book_category WHERE fk_book_id=#{bookId}")
    Integer selectBookCategoryByBookId(int bookId);

    @Insert("INSERT INTO t_book_category (fk_book_id,fk_category_id) VALUES(#{bookId},#{categoryId});")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyColumn = "id", keyProperty = "id", resultType = Integer.class, before = false)
    Integer addBookCategory(int bookId, int categoryId);

    @Delete("DELETE FROM t_book_category WHERE fk_book_id=#{bookId};")
    Integer deleteBookCategory(int bookId);

    /**
     * 注意：从BookServiceImpl中传入的参数是两个Int类型的ID
     * @param bookId
     * @param categoryId
     * @return
     */
    @Update("UPDATE t_book_category SET fk_category_id=#{categoryId} WHERE fk_book_id=#{bookId};")
    Integer updateBookCategory(int bookId, int categoryId);



}
